package com.example.maybeaccount.Spinner;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.os.Bundle;

import com.example.maybeaccount.R;

import java.util.List;

public class SpinnerPopupWindow<T> extends PopupWindow {
    private List<T> datas;//listview数据
    private NormalAdapter adapter;
    private LayoutInflater inflater;
    private ListView mListView;
    private Context mContext; // 上下文参参数

    public SpinnerPopupWindow(Context context, List<T> datas, AdapterView.OnItemClickListener clickListener){
        super(context);
        mContext=context;
        inflater = LayoutInflater.from(context);
        this.datas = datas;
        init(clickListener);
    }

    private void init(AdapterView.OnItemClickListener clickListener){
        View view = inflater.inflate(R.layout.spinner_window_layout, null);
        setContentView(view);
        setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0x00);
        setBackgroundDrawable(dw);
        mListView = (ListView) view.findViewById(R.id.popup_listview);
        adapter = new NormalAdapter(mContext,datas,R.layout.spinner_popup_item);
        mListView.setAdapter(adapter);
        mListView.setOnItemClickListener(clickListener);
    }
}
